package com.spring.mini.demo.controller;

import com.spring.mini.demo.service.IndexService;
import com.spring.mini.framework.annotation.MyAutowired;
import com.spring.mini.framework.annotation.MyController;
import com.spring.mini.framework.annotation.MyRequestMapping;
import com.spring.mini.framework.annotation.MyRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Tinu 1810989@qq.com
 */
@MyController
@MyRequestMapping("/index")
public class IndexController {

    @MyAutowired
    private IndexService indexService;

    @MyRequestMapping("/getName")
    public void getName(HttpServletRequest req, HttpServletResponse resp,@MyRequestParam("name") String name) {
        try {
            resp.setCharacterEncoding("utf-8");
            resp.getWriter().write(indexService.getName(name));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/add")
    public void getAdd(HttpServletResponse resp,int a, int b) {
        try {
            resp.setCharacterEncoding("utf-8");
            resp.getWriter().write("a + b = "+(a+b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/sub")
    public String getSub(int a, int b) {

        return "a - b = "+(a-b);

    }
}
